package com.steve.summary.saga.编制式.domain;

/**
 * @Author: STEVE
 * @Description: SAGA步骤，包含一个正向操作和一个补偿操作
 * @since: 2025-06-05
 */
public class SagaStep {

    // 步骤名称
    private String stepName;
    // 正向操作
    private Runnable action;
    // 补偿操作
    private Runnable compensation;

    public SagaStep(String stepName, Runnable action, Runnable compensation) {
        this.stepName = stepName;
        this.action = action;
        this.compensation = compensation;
    }

    /**
     * 执行正向操作
     */
    public void execute() {
        action.run();
    }

    /**
     * 执行补偿操作
     */
    public void compensate() {
        compensation.run();
    }

    /**
     * 获取步骤名称
     */
    public String getStepName() {
        return stepName;
    }

}
